import 'package:flutter/material.dart';

class ClickUtils {
  static Map routeMap = {};
  static VoidCallback? goGuide;

  static int clicks = 0;
  static int jumpTime = 0;
  static Function? downFn;

  ///防止多次点击
  static VoidCallback debounce(Function fn, [int t = 500]) {
    return () {
      if (downFn != fn) {
        clicks = 0;
        downFn = fn;
        jumpTime = 0;
      }
      if (jumpTime >= (DateTime.now().millisecondsSinceEpoch - t) &&
          clicks <= 10) {
        clicks++;
        jumpTime = DateTime.now().millisecondsSinceEpoch;
      } else {
        jumpTime = DateTime.now().millisecondsSinceEpoch;
        clicks = 0;
        fn();
      }
    };
  }
}
